package com.community.zhihuishequ.component;

import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;

import com.blankj.utilcode.util.Utils;
import com.community.zhihuishequ.BuildConfig;
import com.community.zhihuishequ.view.monitor.MonitorController;
import com.raizlabs.android.dbflow.config.FlowConfig;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;

public class CommunityApplication extends MultiDexApplication {

    private static CommunityApplication instance;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Utils.init(this);

        instance = this;

        Bugly.init(getApplicationContext(), "f2730936cd", false);
        initBuglyHotFix();

        //  启动海康SDK
        MonitorController.getInstance().init();

        FlowManager.init(this);
    }

    public static Context getContext() {
        return instance.getApplicationContext();
    }

    private void initBuglyHotFix() {
        // 设置是否开启热更新能力，默认为true
        Beta.enableHotfix = true;
        // 设置是否自动下载补丁，默认为true
        Beta.canAutoDownloadPatch = true;
        // 设置是否自动合成补丁，默认为true
        Beta.canAutoPatch = true;
        // 设置是否提示用户重启，默认为false
        Beta.canNotifyUserRestart = false;

        Bugly.init(this, "91c5d02754", true);
        Bugly.setIsDevelopmentDevice(this, BuildConfig.DEBUG);
        Beta.checkUpgrade();
    }
}
